package com.yic.module.wms.dal.mysql.erpproducein;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.wms.dal.dataobject.erpproducein.ErpProduceInDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.wms.controller.admin.erpproducein.vo.*;

/**
 * erp生产入库 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface ErpProduceInMapper extends BaseMapperX<ErpProduceInDO> {

    default PageResult<ErpProduceInDO> selectPage(ErpProduceInPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ErpProduceInDO>()
                .eqIfPresent(ErpProduceInDO::getFactoryId, reqVO.getFactoryId())
                .eqIfPresent(ErpProduceInDO::getWorkshopId, reqVO.getWorkshopId())
                .eqIfPresent(ErpProduceInDO::getCode, reqVO.getCode())
                .eqIfPresent(ErpProduceInDO::getErpDocNo, reqVO.getErpDocNo())
                .eqIfPresent(ErpProduceInDO::getErpDocCode, reqVO.getErpDocCode())
                .betweenIfPresent(ErpProduceInDO::getErpDocDate, reqVO.getErpDocDate())
                .eqIfPresent(ErpProduceInDO::getErpCenterCode, reqVO.getErpCenterCode())
                .eqIfPresent(ErpProduceInDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(ErpProduceInDO::getItemId, reqVO.getItemId())
                .eqIfPresent(ErpProduceInDO::getBatchNo, reqVO.getBatchNo())
                .eqIfPresent(ErpProduceInDO::getStatus, reqVO.getStatus())
                .orderByDesc(ErpProduceInDO::getId));
    }

    default List<ErpProduceInDO> selectList(ErpProduceInExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ErpProduceInDO>()
                .eqIfPresent(ErpProduceInDO::getCode, reqVO.getCode())
                .eqIfPresent(ErpProduceInDO::getErpDocNo, reqVO.getErpDocNo())
                .eqIfPresent(ErpProduceInDO::getErpDocCode, reqVO.getErpDocCode())
                .betweenIfPresent(ErpProduceInDO::getErpDocDate, reqVO.getErpDocDate())
                .eqIfPresent(ErpProduceInDO::getErpCenterCode, reqVO.getErpCenterCode())
                .eqIfPresent(ErpProduceInDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(ErpProduceInDO::getBatchNo, reqVO.getBatchNo())
                .eqIfPresent(ErpProduceInDO::getStatus, reqVO.getStatus())
                .orderByDesc(ErpProduceInDO::getId));
    }

    default ErpProduceInDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<ErpProduceInDO>()
                .eq(ErpProduceInDO::getCode, code));
    }

    default List<ErpProduceInDO> selectByPlanId(Long planId, Integer status) {
        return selectList(new LambdaQueryWrapperX<ErpProduceInDO>()
                .eqIfPresent(ErpProduceInDO::getPlanId, planId)
                .eqIfPresent(ErpProduceInDO::getStatus, status));
    }
}
